import Vue from 'vue'
import VueRouter from 'vue-router'

// 引入模板文件并懒加载
const home = () =>import('../views/home/home')
const cart = () =>import('../views/cart/cart')
const sort = () =>import('../views/sort/sort')
const user = () =>import('../views/user/user')
// 安装插件
Vue.use(VueRouter)

// cli3.0值后再次点击当前页面时候会报错,增加以下代码不会报错
const VueRouterPush = VueRouter.prototype.push 
VueRouter.prototype.push = function push (to) {
    return VueRouterPush.call(this, to).catch(err => err)
}

const routes = [
	{
		path:'',
		redirect: '/home'
	},
	{
		path:'/home',
		component: home
	},
	{
		path:'/cart',
		component: cart
	},
	{
		path: '/sort',
		component: sort,
	},
	{
		path:'/user',
		component: user
	}
]
// 创建router
const router = new VueRouter({
	routes,
	mode:'history'
})

export default router